package com.qnbc.mystery.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.qnbc.mystery.core.annotation.Log;
import com.qnbc.mystery.core.controller.BaseController;
import com.qnbc.mystery.core.domain.AjaxResult;
import com.qnbc.mystery.core.enums.BusinessType;
import com.qnbc.mystery.core.page.TableDataInfo;
import com.qnbc.mystery.core.utils.poi.ExcelUtil;
import com.qnbc.mystery.pojo.domain.PmsFeightTemplate;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qnbc.mystery.service.IPmsFeightTemplateService;

/**
 * 运费模版
 *
 * @author guzj
 * @date 2024-01-24
 */
@Api("运费模版")
@RestController
@RequestMapping("/mystery/template")
public class PmsFeightTemplateController extends BaseController {
    @Autowired
    private IPmsFeightTemplateService pmsFeightTemplateService;

    /**
     * 查询运费模版列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PmsFeightTemplate pmsFeightTemplate) {
        startPage();
        List<PmsFeightTemplate> list = pmsFeightTemplateService.selectPmsFeightTemplateList(pmsFeightTemplate);
        return getDataTable(list);
    }

    /**
     * 导出运费模版列表
     */
    @Log(title = "运费模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsFeightTemplate pmsFeightTemplate) {
        List<PmsFeightTemplate> list = pmsFeightTemplateService.selectPmsFeightTemplateList(pmsFeightTemplate);
        ExcelUtil<PmsFeightTemplate> util = new ExcelUtil<PmsFeightTemplate>(PmsFeightTemplate.class);
        util.exportExcel(response, list, "运费模版数据");
    }

    /**
     * 获取运费模版详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(pmsFeightTemplateService.selectPmsFeightTemplateById(id));
    }

    /**
     * 新增运费模版
     */
    @Log(title = "运费模版", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsFeightTemplate pmsFeightTemplate) {
        return toAjax(pmsFeightTemplateService.insertPmsFeightTemplate(pmsFeightTemplate));
    }

    /**
     * 修改运费模版
     */
    @Log(title = "运费模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsFeightTemplate pmsFeightTemplate) {
        return toAjax(pmsFeightTemplateService.updatePmsFeightTemplate(pmsFeightTemplate));
    }

    /**
     * 删除运费模版
     */
    @Log(title = "运费模版", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pmsFeightTemplateService.deletePmsFeightTemplateByIds(ids));
    }
}
